<template>
  <div class="card-out-container">
    <a-form layout="inline" v-if="showMore">
      <a-form-item :label="$t('deviceManage.equipmentCode')">
        <a-input v-model:value.trim="queryParam.code" :placeholder="$t('deviceManage.equipmentCode')" @keyup.enter="loadData" allowClear />
      </a-form-item>
      <a-form-item :label="$t('common.state')">
        <a-select v-model:value="queryParam.status" allowClear :placeholder="$t('common.pleaseSelect')">
          <a-select-option :value="0">{{ $t('sysManage.normal') }}</a-select-option>
          <a-select-option :value="1">{{ $t('common.stop') }}</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item>
        <a-space>
          <a-button type="primary" @click="loadData">{{ $t('common.see') }}</a-button>
          <a-button @click="searchReset">{{ $t('common.reset') }}</a-button>
        </a-space>
      </a-form-item>
    </a-form>
    <CustomTable storeTableName="terminalDeviceList" rowKey="id" :loading="loading" :dataSource="dataSource" :columns="columns" :rowSelection=" isEnvLocal ? null:{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, getCheckboxProps: checkboxProps, fixed: 'left'}" :pagination="ipagination" :scroll="{y: showMore? 'calc(100vh - 395px)' : 'calc(100vh - 320px)'}" @change="handleTableChange" :showMore="showMore">
      <template #operateLeft>
        <div class="operate-left">
          <a-button type="primary" @click="handleEdit({status:0},false)">{{ $t('common.add') }}</a-button>
          <a-button type="warning" ghost :disabled="!selectedRowKeys.length" @click="handleDelete(null)">{{ $t('common.delMore') }}</a-button>
        </div>
      </template>
      <template #operateRight>
        <div class="slot-operate-right">
          <a-input-search v-model:value.trim="fuzzySearch" enter-button :placeholder="$t('deviceManage.equipmentCode')" v-if="!showMore" @search="loadData" />
          <a-button class="ml-10" @click="toggleMore" type="primary" ghost>{{ $t('common.highFilter') }}</a-button>
        </div>
      </template>
      <template #bodyCell="{ scope }">
        <template v-if="scope.column.key === 'code'">
          <span>{{scope.record.code}}</span>
        </template>
        <template v-else-if="scope.column.key === 'loginStatus'">
          <a-tag class="tag-green" v-if="scope.record.loginStatus == 2"> {{ $t('other.onLine') }}</a-tag>
          <a-tag class="tag-gray2" v-if="scope.record.loginStatus == 1"> {{ $t('other.offLine') }}</a-tag>
        </template>
        <template v-else-if="scope.column.key === 'status'">
          <a-switch :checked="!Boolean(scope.record.status)" @change="(value) => changeStatus(value, scope.record)" />
        </template>
        <template v-else-if="scope.column.key === 'operate'">
          <span class="table-operate-container">
            <a-button type="link" class="primary-link" @click="handleEdit(scope.record)">{{ $t('common.editor') }}</a-button>
            <a-divider type="vertical" />
            <a-button type="link" class="warning-link" :disabled="!Boolean(scope.record.status)" @click="handleDelete(scope.record.id)">{{ $t('common.del') }}</a-button>
          </span>
        </template>
      </template>
    </CustomTable>
    <OperateModal ref="modalForm" @ok="loadData" />
  </div>
</template>

<script>
import { ListMixinPm } from '@/mixin/listMixinPm.js'
import CustomTable from '@/components/commonTable/customTable.vue'
import OperateModal from './modules/operateModal.vue'
import { columns } from './modules/config'
export default {
  name: 'terminalDevice',
  mixins: [ListMixinPm],
  components: {
    OperateModal,
    CustomTable
  },
  data () {
    return {
      url: {
        list: '/api/device/terminal-device/list',
        delete: '/api/device/terminal-device/delete',
        save: '/api/device/terminal-device/edit'
      },
      columns: columns,
      fuzzySearchName: 'code',
    }
  },
  created () {

  }
}
</script>